<template>
  <div class="detail-paga flex flex-col flex-1 bg-[#f5f5f5]">
    <Header :header-tip="t('advisoryNotice')" />
    <BreadCrumb :title="title" />
    <AdvisoryNoticeDetailContent :data="contentData" />
    <div class="flex justify-center mt-[18px] mb-[80px]">
      <el-button class="w-[100px]" @click="handleClose">
        {{ t('common.close') }}
      </el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { queryAnnouncementInfo } from '~/api/api-cms'

const route = useRoute()
const { t } = useI18n()
const title = ref('')
const contentData = ref({})

interface Params {
  uuid: string
}
const getDetail = async (params: Params): Promise<void> => {
  const res = await queryAnnouncementInfo(params)
  if (res?.code === '200') {
    contentData.value = res.data
    title.value = res.data?.title
  }
}

const handleClose = () => {
  // 关闭当前窗口
  window.close()

  // 如果 window.close() 不起作用（这在某些情况下会发生）
  // 可以提供后备方案，比如返回上一页
  if (window.opener) {
    // 如果是从另一个窗口打开的，尝试通知父窗口
    window.opener.postMessage({ action: 'closeAdvisoryDetail' }, '*')
  }
  else {
    // 作为最后的手段，可以返回上一页或重定向到列表页
    window.history.back()
    // 或者
    // window.location.href = '/advisoryNotice'
  }
}
onMounted(async () => {
  await nextTick()
  getDetail({ uuid: route.query.id as string })
})

definePageMeta({
  ssr: false,
})
</script>

<style lang="scss" scoped>

</style>
